<template>
  <a-card :bordered="false" style="border-radius: 10px;">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="6" :sm="8">
            <a-form-item label="发行方名称">
              <a-input placeholder="请输入发行方名称" v-model="queryParam.factoryName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="联系人">
              <a-input placeholder="请输入联系人" v-model="queryParam.name"></a-input>
            </a-form-item>
          </a-col>
          <template>
            <a-col :md="6" :sm="8">
              <a-form-item label="联系电话">
                <a-input placeholder="请输入联系电话" v-model="queryParam.phone"></a-input>
              </a-form-item>
            </a-col>
          </template>
          <a-col :md="6" :sm="8" >
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    
    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" v-if="userAuth2btn=='2' || userAuth2btn=='3'" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" style="background: #00c39b;border: 1px solid #00c39b;" v-if="userAuth2btn=='2' || userAuth2btn=='3'" key="1" @click="handleApplyYes">通过</a-button>
      <a-button type="primary" style="background: #ff4767;border: 1px solid #ff4767;" v-if="userAuth2btn=='2' || userAuth2btn=='3'" @click="modal2Visible=true;failVal=''">拒绝</a-button>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px" v-if="userAuth2btn=='2' || userAuth2btn=='3'"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div class="styXcl">
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange, type:'radio'}"
        :customRow="clickThenSelect"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无此图片</span>
          <div v-else @click="jumpProview(text)">
            <img :src="getImgView(text)" height="25px" alt="图片不存在" style="max-width:80px;font-size: 12px;font-style: italic;"/>
          </div>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无此文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="uploadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <!-- <a v-if="record.status == 0" @click="handleEdit(record)">编辑</a>

          <a-divider v-if="userAuth2btn=='3'" type="vertical" /> -->
           <a-popconfirm title="确定删除吗?" v-if="userAuth2btn=='3'" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
          <!-- <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
               c
              </a-menu-item>
            </a-menu>   
          </a-dropdown> --> 
        </span>

      </a-table>
    </div>
    <a-tabs defaultActiveKey="1">
      <a-tab-pane tab="发行方店家" key="1" >
        <block-manufacturer-user-list :mainId="selectedMainId" :showAdd="showAdd" />
      </a-tab-pane>
    </a-tabs>
    <JProviewImg v-if="showImg" @closeProview="closeProview" :imgurl="proviewUrl"></JProviewImg>
    <blockManufacturerInfo-modal  ref="modalForm" @ok="modalFormOk"></blockManufacturerInfo-modal>
    <a-modal
      title="拒绝理由"
      centered
      v-model="modal2Visible"
      @ok="handleApplyNo()"
    >
      <a-textarea v-model="failVal" maxlength="50"></a-textarea>
    </a-modal>
  </a-card>
</template>

<script>  
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import BlockManufacturerInfoModal from './modules/BlockManufacturerInfoModal'
  import { getAction,putAction } from '@/api/manage'
  
  import BlockManufacturerUserList from './BlockManufacturerUserList'
  import JDictSelectTag from '@/components/dict/JDictSelectTag.vue'
  import JDate from '@/components/jeecg/JDate.vue'
  import JProviewImg from '@/components/jeecg/JProviewImg.vue'
  import {initDictOptions, filterMultiDictText} from '@/components/dict/JDictSelectUtil'
  import { disabledAuthFilter } from "@/utils/authFilter"

  export default {
    name: "BlockManufacturerInfoList",
    mixins:[JeecgListMixin],
    components: {
      JDictSelectTag,
      JDate,
      JProviewImg,
      BlockManufacturerUserList,
      BlockManufacturerInfoModal
    },
    data () {
      return {
        modal2Visible:false,
        failVal:"",
        showAdd:false,
        toggleSearchStatus:"",
        showImg:false,
        proviewUrl:"",
        description: '发行方信息管理页面',
        // 表头
        columns: [
          {
            title:'发行方名称',
            align:"center",
            dataIndex: 'factoryName'
          },
          {
            title:'企业简介',
            align:"center",
            dataIndex: 'companyProfile'
          },
          {
            title:'创建日期',
            align:"center",
            dataIndex: 'createTime'
          },
          // {
          //   title:'生产商类型',
          //   align:"center",
          //   dataIndex: 'type'
          // },
          {
            title:'联系人',
            align:"center",
            dataIndex: 'linkName'
          },
          {
            title:'审核状态',
            align:"center",
            dataIndex: 'status',
            customRender:(text)=>{
                return filterMultiDictText(this.dictOptions['status'], text+"")
            }
          },
          {
            title:'经营地址',
            align:"center",
            dataIndex: 'address'
          },
          {
            title:'联系电话',
            align:"center",
            dataIndex: 'phone'
          },
          {
            title:'企业LOGO',
            align:"center",
            dataIndex: 'imageurl',
            scopedSlots: {customRender: 'imgSlot'}
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            scopedSlots: { customRender: 'action' },
          }
        ],
        url: {
          list: "/block/blockManufacturerInfo/list",
          delete: "/block/blockManufacturerInfo/delete",
          deleteBatch: "/block/blockManufacturerInfo/deleteBatch",
          exportXlsUrl: "/block/blockManufacturerInfo/exportXls",
          importExcelUrl: "block/blockManufacturerInfo/importExcel",
          apply: "block/blockManufacturerInfo/apply",
        },
        dictOptions:{
         status:[],
        },
        /* 分页参数 */
        ipagination:{
          current: 1,
          pageSize: 5,
          pageSizeOptions: ['5', '10', '50'],
          showTotal: (total, range) => {
            return range[0] + "-" + range[1] + " 共" + total + "条"
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0
        },
        selectedMainId:'',
        userAuth2btn:"1"
      }  
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      }
    },
    mounted() {
      getAction("/block/blockManufacturerInfo/userAuth2btn")
        .then(res => {
          if (res.success) {
            this.userAuth2btn = res.result.status;
          } else {
            this.$message.warning(res.message)
          }
        })
    },
    methods: {
      isDisabledAuth(code){
        return disabledAuthFilter(code);
      },
      closeProview(){
        this.showImg = false;
      },
      jumpProview(val){
        this.showImg = true;
        this.proviewUrl = window._CONFIG['imgDomainURL']+'/'+val;
      },
      initDictConfig(){
        initDictOptions('apply_status').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'status', res.result)
          }
        })
      },
      clickThenSelect(record) {
        return {
          on: {
            click: () => {
              this.onSelectChange(record.id.split(","), [record]);
            }
          }
        }
      },
      onClearSelected() {
        this.selectedRowKeys = [];
        this.selectionRows = [];
        this.selectedMainId=''
      },
      onSelectChange(selectedRowKeys, selectionRows) {
        this.showAdd = false;
        if(selectionRows[0].status == 1){
          this.showAdd = true;
        }
        this.selectedMainId=selectedRowKeys[0]
        this.selectedRowKeys = selectedRowKeys;
        this.selectionRows = selectionRows;
      },
       handleApplyYes: function() {
      this.applyMethod(this, 1)
    },
    handleApplyNo: function() {
      if(!this.failVal){
        this.$message.warning('请输入拒绝理由！');
        return;
      }
      this.modal2Visible = false;
      this.applyMethod(this, 2)
    },
    applyMethod: function(that, status) {
      var ids = '';
      if (that.selectedRowKeys.length <= 0) {
        that.$message.warning('请选择一条记录！')
        return
      }
      for (var a = 0; a < that.selectedRowKeys.length; a++) {
        ids += that.selectedRowKeys[a] + ','
      }
      if(status == 2){
        var listVal = { ids: ids, status: status,statusFailReason:this.failVal };
      }else{
        var listVal = { ids: ids, status: status };
      }
      putAction(that.url.apply, listVal)
        .then(res => {
          if (res.success) {
            that.$message.success(res.message)
            that.loadData()
            that.onClearSelected()
          } else {
            that.$message.warning(res.message)
          }
        })
    },
      loadData(arg) {
        if(!this.url.list){
          this.$message.error("请设置url.list属性!")
          return  
        }
        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1;
        }
        this.onClearSelected()
        var params = this.getQueryParams();//查询条件
        this.loading = true;
        getAction(this.url.list, params).then((res) => {
          if (res.success) {
            this.dataSource = res.result.records;
            this.ipagination.total = res.result.total;
          }
          if(res.code===510){
            this.$message.warning(res.message)
          }
          this.loading = false;
        })
      }

    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
  .styXcl /deep/ .ant-table-align-center{
    min-width:100px;
    max-height:100px;
  }
  .verMidel{
    display: inline-block;
    height: 42px;
    line-height: 42px;
  }
  .inputSty{
    padding: 8px;
    height: 42px;
    box-sizing: border-box;
  }
</style>